package com.zenika.zenbinding.client.converter;

import com.zenika.zenbinding.client.exception.ConverterException;

/**
 * Converter for the Boolean class.
 * @author Zenika
 */
public class BooleanConverter implements Converter {

	public String fromObjectToString(Object object) throws ConverterException {
		try {
			Boolean value = (Boolean) object;
			return value.toString();
		} catch (ClassCastException e) {
			throw new ConverterException("The object is not a boolean");
		}
	}

	public Object fromStringToObject(String string) throws ConverterException {
		try {
			// FIXME le Contructeur de Boolean ne renvoie jamais d'erreur mais
			// false a la place
			return new Boolean(string);
		} catch (Exception e) {
			throw new ConverterException("The string " + string + " doesn't represent a boolean");
		}
	}

}
